package com.jsbj.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jsbj.user.entities.SysProject;
import com.jsbj.user.service.ISysProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

/**
 * <p>
 * 项目表 服务实现类
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@Service
public class SysProjectService {

    @Autowired
    private ISysProjectService sysProjectService;


    public SysProject getProjectInfoByTenatCode(String tenantCode) {
        LambdaQueryWrapper<SysProject> wrapper = new LambdaQueryWrapper();
        wrapper.eq(SysProject::getDisabled, 0);
        wrapper.eq(SysProject::getTenantCode, tenantCode);
        wrapper.last(" limit 1 ");
        SysProject info = sysProjectService.getOne(wrapper);
        try {
            if (info!=null && null != info.getStartDate()) {
                // 把开工日期转成string
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dateString = formatter.format(info.getStartDate());
                info.setStartDateStr(dateString);
            }
            if (info!=null && null != info.getEndDate()) {
                // 把开工日期转成string
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                String dateString = formatter.format(info.getEndDate());
                info.setEndDateStr(dateString);
            }

        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return info;
    }

}
